package com.zfast.config.config;

import com.zfast.config.interceptor.LogInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Classname MvcConfig
 * @Description None
 * @Date 2019/7/16 10:08
 * @Created by WDD
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Bean
    public LogInterceptor setBean() {
        return new LogInterceptor(); // 注入spring
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //region swagger3
        /*registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);*/
        //endregion

        //region swagger2.8
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        //endregion
        //front_001
        /*registry.addResourceHandler("/templates/**")
                .addResourceLocations("classpath:/templates/")
                .resourceChain(false);*/
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(setBean())
                .addPathPatterns("/badminton/**")
                .excludePathPatterns("/static/**", "/", "/badminton/login");
        //front_002
        /*registry.addInterceptor(setBean())
                //.addPathPatterns("/badminton/**")
                .excludePathPatterns("/static/**", "/", "/badminton/login","/templates/**");*/
    }
}
